using System.IO;
using UnityEngine;

namespace PKGames.AssetBundleSystem
{
	public class FileAssetBundleLoader : AssetBundleLoader
	{
		private string _filePath = string.Empty;

		private bool _isDone;

		public FileAssetBundleLoader(string assetBundleName, string url)
		{
			_assetBundleName = assetBundleName;
			_filePath = url + _assetBundleName;
			_assetBundle = AssetBundleCache.GetCachedAssetBundle(_assetBundleName);
			_isDone = false;
		}

		public override void Start()
		{
			if (_assetBundle == null && File.Exists(_filePath))
			{
				_assetBundle = AssetBundle.LoadFromFile(_filePath);
				AddAssetBundleToCache(_assetBundleName, _assetBundle);
			}
			_isDone = true;
		}

		public override bool IsDone()
		{
			return _isDone;
		}

		public override float GetProgress()
		{
			return (!_isDone) ? 0f : 1f;
		}

		public override string GetError()
		{
			return string.Empty;
		}

		public override AssetBundle GetAssetBundle()
		{
			return _assetBundle;
		}

		public override void Cleanup()
		{
		}
	}
}
